Skip to content

Honor multipart boundary from an explicit Content-Type header#1896

Open
Synvoya wants to merge 1 commit into
httpie:masterfrom
Synvoya:fix/multipart-boundary-from-content-type
Open

Honor multipart boundary from an explicit Content-Type header#1896
Synvoya wants to merge 1 commit into
httpie:masterfrom
Synvoya:fix/multipart-boundary-from-content-type

Conversation

@Synvoya

@Synvoya Synvoya commented Jul 11, 2026

Copy link
Copy Markdown

Description

When a multipart boundary is supplied only via an explicit Content-Type header (without the --boundary flag), HTTPie declares that boundary in the header but writes the body with a different, random boundary — so the declared boundary never appears in the body and the request is unparseable.

$ http --offline --multipart POST example.org hello=world \
    'Content-Type:multipart/form-data; boundary=xoxo'
# header says boundary=xoxo, but the body delimiter is --<random>

This is the workflow requested in #199 (setting the boundary the way curl does).

Fix

If no --boundary was given, read the boundary from the Content-Type header (via the existing parse_content_type_header, which is case-insensitive and quote-stripping, so Boundary="..." works too) and use it for the encoder. --boundary still takes precedence, so the explicit-override behavior is unchanged.

Test

Added test_multipart_boundary_from_content_type_without_flag. Full tests/test_uploads.py passes (28); reverting only the fix fails the new test.

When a multipart boundary was supplied only via a Content-Type header (no
--boundary flag), HTTPie declared that boundary in the header but wrote the
body with a different random boundary, producing an unparseable request.
Reconcile the encoder's boundary with the one declared in the header;
--boundary still takes precedence.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant